package com.ruoyi.location.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.location.controller.vo.QuickReportVo;
import com.ruoyi.location.repository.QuickReportRepository;
import com.ruoyi.location.repository.generator.entity.QuickReportLocation;
import com.ruoyi.location.service.AppService;
import com.ruoyi.location.service.QuickReportService;
import com.ruoyi.location.vo.req.LocationReportReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.MediaType;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/nosso/quickreport")
public class QuickReportController extends BaseController {

    @Autowired
    private QuickReportService quickReportService;
    @Autowired
    private QuickReportRepository quickReportRepository;

    @PostMapping("/put")
    public Object insertQuickReportLocation(@RequestBody QuickReportVo quickReportVo) {
        int a = quickReportService.insertQuickReportLocation(quickReportVo);
        return AjaxResult.success();
    }

    @PostMapping(value = "/putForm", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public Object insertQuickReportLocationForm(@RequestParam String room,
                                              @RequestParam String name,
                                              @RequestParam Double longitude,
                                              @RequestParam Double latitude) {
        QuickReportVo quickReportVo = new QuickReportVo();
        quickReportVo.setRoom(room);
        quickReportVo.setName(name);
        quickReportVo.setLongitude(longitude);
        quickReportVo.setLatitude(latitude);
        int a = quickReportService.insertQuickReportLocation(quickReportVo);
        return AjaxResult.success();
    }

    @GetMapping("/get")
    public Object selectLatestByRoomGroupByName(@RequestParam(value = "room") String room) {
        List<QuickReportLocation> list = quickReportRepository.selectLatestByRoomGroupByName(room);
        return AjaxResult.success(list);
    }

    @GetMapping("/list")
    public Object listLocationsByRoom(@RequestParam(value = "room") String room,
                                      @RequestParam(value = "dayType") String dayType) {
        Map<String, List<QuickReportLocation>> res = quickReportRepository.listLocationsByRoom(room, dayType);
        return AjaxResult.success(res);
    }

}
